package work;

/**
 * @TODO
 * @Author xu
 * 2025/2/24
 */
public class Day3_11 {
    public static void main(String[] args) {
        int terms = 1000000;
        double piEstimate = calculatePi(terms);
        System.out.printf("使用 %d 项计算的 π 的近似值为: %.7f%n", terms, piEstimate);
    }
    public static double calculatePi(int terms) {
        double sum = 0.0;
        for (int n = 0; n < terms; n++) {
            sum += Math.pow(-1, n) / (2 * n + 1);
        }
        return 4 * sum;
    }
}
